package com.xgz.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xgz.dao.SclPlaneDao;
import com.xgz.dao.SclRecordDao;
import com.xgz.entity.*;
import com.xgz.service.SclRecondTestService;
import com.xgz.dao.SclRecondTestDao;


import com.xgz.service.SclRecordService;
import org.apache.commons.beanutils.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpRequest;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.lang.reflect.InvocationTargetException;
import java.util.List;
import java.util.Map;

/**
 * (SclRecondTest)表服务实现类
 *
 * @author makejava
 * @since 2022-11-09 14:50:42
 */
@Service
public class SclRecondTestServiceImpl implements SclRecondTestService {
    @Autowired
    private SclRecondTestDao sclRecondTestDao;

    /**
     * 查询、条件查询
     *
     * @param myPage
     * @param sclRecondTest
     * @return
     */
    @Override
    public PageInfo querySclRecondTest(MyPage myPage, SclRecondTest sclRecondTest) {
        PageHelper.startPage(myPage.getPage(), myPage.getLimit());
        PageInfo<SclRecondTest> sclRecondTestPageInfo = new PageInfo<>(sclRecondTestDao.querySclRecondTest(sclRecondTest));
        return sclRecondTestPageInfo;
    }

    /**
     * 添加
     *
     * @param sclRecondTest
     * @return
     */
    @Override
    public boolean addAndupd(SclRecondTest sclRecondTest, HttpSession session, HttpServletRequest request) {
        //获取rid rusername tel
        Integer rid = Integer.valueOf(request.getParameter("rid"));
        String rusername = request.getParameter("rusername");
        String tel = request.getParameter("tel");
        String recond = request.getParameter("recond");
        String remark = request.getParameter("remark");
        //给 rid rusername tel 赋值
        sclRecondTest.setRid(rid);
        sclRecondTest.setRusername(rusername);
        sclRecondTest.setTel(tel);
        sclRecondTest.setRecond(recond);
        sclRecondTest.setRemark(remark);
        //获取创建人（登陆的用户名）
        TUser user = (TUser) session.getAttribute("user");
        sclRecondTest.setCreatename(user.getUsername());
        int i = sclRecondTestDao.addAndupd(sclRecondTest);
        return i > 0 ? true : false;
    }

    /**
     * 修改
     * @param sclRecondTest
     * @return
     */
    @Override
    public boolean updSclRecondTest(SclRecondTest sclRecondTest, HttpSession session) {
        //获取修改人（登陆的用户名）
        TUser user = (TUser) session.getAttribute("user");
        ///System.out.println("user = " + user);
        sclRecondTest.setUpdatename(user.getUsername());
        if (sclRecondTest.getId() != null) {
            int i = sclRecondTestDao.updSclRecondTest(sclRecondTest);
            //System.out.println("回访修改i = " + i);
            return true;
        }
        return false;
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @Override
    public boolean delSclRecondTest(Integer id) {
        int i = sclRecondTestDao.delSclRecondTest(id);
        return i > 0 ? true : false;
    }

    /**
     * 批量删除
     * @param id
     * @return
     */
    @Override
    public boolean delSclRecondTestbath(Integer[] id) {
        int i = sclRecondTestDao.delSclRecondTestbath(id);
        return i > 0 ? true : false;
    }
}

